using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;

public partial class WebUserControl : System.Web.UI.UserControl
{
    private SqlConnection _oleConn;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Common.accCodeValue = 0;
            //Common.accTypeValue = 0;
            DropDownList1.SelectedIndex = 0;
            DropDownList1_SelectedIndexChanged1(null, null);
            //Common.accTypeValue = Convert.ToInt32(DropDownList1.SelectedValue);
        }
    }
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        string con = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        //string con = @"Provider=SQLSql;Data Source=CSE-PC\SQLEXPRESS;User ID=sa;Initial Catalog=DB2011;Password=1234";
        StringBuilder sv = new StringBuilder(con);

        if (DropDownList1.SelectedValue.Length > 0)
        {
            //TextBox1.Text = DropDownList1.SelectedValue.Trim() + "(type) ";
            Common.accTypeValue = int.Parse(DropDownList1.SelectedValue.ToString());
            Common.accTypeName = DropDownList1.SelectedItem.Text;
            _oleConn = new SqlConnection();
            _oleConn.ConnectionString = sv.ToString();
            string cmd1 = "SELECT ACCNAME,ACCCODE FROM ACCOUNT WHERE ACCTYPE=" + DropDownList1.SelectedValue.Trim() + "and acccode is not NULL and accname is not NULL and ( accclose = 'false' or accclose is NULL ) order by accname";

            SqlCommand comm = new SqlCommand(cmd1, _oleConn);

            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();

            da.SelectCommand = comm;
            da.Fill(ds, "Accounts");

            if (ds.Tables[0].Rows.Count > 0)
            {
                DropDownList2.DataSource = ds.Tables[0];
                DropDownList2.DataBind();

                DropDownList2.SelectedIndex = 0;
                DropDownList2_SelectedIndexChanged(null, null);
            }
            else
            {
                DropDownList2.Items.Clear();
                DropDownList2.DataBind();

            }
        }
    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        Common.accCodeValue = int.Parse(DropDownList2.SelectedValue.ToString());
        Common.accCodeName = DropDownList2.SelectedItem.Text;
    }
}
